from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField
from wtforms.validators import DataRequired, ValidationError
from app.models import Skill

class SkillForm(FlaskForm):
    name = StringField('技能名称', validators=[DataRequired()])
    submit = SubmitField('保存')
    
    def validate_name(self, name):
        skill = Skill.query.filter_by(name=name.data).first()
        if skill is not None:
            raise ValidationError('该技能标签已存在。')